package com.peng.kslc;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A7NumReverse
 *
 * @author lupeng
 * Created on 2022-07-24
 */
public class A7NumReverse {

    private static final Logger logger = LoggerFactory.getLogger(A7NumReverse.class);

    public static void main(String[] args) {
        System.out.println(new A7NumReverse().reverse(-123));
    }

    public int reverse(int x) {
        int result = 0;
        while (x != 0) {
            if (result < Integer.MIN_VALUE / 10 || result > Integer.MAX_VALUE / 10) {
                return 0;
            }
            int temp = x % 10;
            x /= 10;
            result = result * 10 + temp;
        }
        return result;
    }
}
